<?php 
namespace app\obd\model;
use think\Config;
use think\Model;

/**
 * 车辆品牌管理
 * @author 王涛
 * @DataTime 2018-08-11T19:45:12+0800
 */
class CarModel extends Model
{
    protected $table = "orange_carmodel";
    protected $connection  = 'carstation';

   
	public function selectcar($w,$world){
        $result = $this
                  ->field("ID,NAME,LOGO_PATH")
                  ->where($w)
                  ->order("INITIALED asc")
                  ->select();
        return $result ;
    }
    public function selectcarList($w,$world,$pagenum,$listNum){
            $result["list"] = $this
                ->field("ID,NAME,LOGO_PATH")
                ->where($w)
                ->page($pagenum,$listNum)
                ->order("INITIALED asc")
                ->select();
            $result["total"] = $this
                             ->where($w)
                             ->count();
            return $result;
    }
    public function deleteCarop($w){
        $result = $this
                ->where($w)
                ->update(["CAR_STATUS"=>9]);
        return $result;
    }
    public function ishasChild($caropID){
        $result = $this
            ->field("ID,NAME,LOGO_PATH")
            ->where(["P_ID"=>$caropID])
            ->limit(1)
            ->order("INITIALED asc")
            ->find();
        return $result;
}
    /**
     * 查询车辆品牌列表
     * @author 王涛
     * @DataTime 2018-08-11T19:45:12+0800
     */
    public function cartypeList($w,$offset, $limit)
    {
        //NAME              名称
        //LOGO_PATH          图标路径
        //CREATE_TIME       创建时间
        //MODIFY_TIME       修改时间
        //SUPPORT_OBD       是否支持OBD
        // $data = $this->where($where)->limit($offset, $limit)->order('ctime desc')->select();
        $data = $this->where($w)
                     ->field('ID,NAME,LOGO_PATH,CREATE_TIME,MODIFY_TIME')
                     ->limit($offset, $limit)
                     ->order('ID')
                     ->select();
        return $data;
    }
    /**
     * 查询车辆品牌详情
     * @author 王涛
     * @DataTime 2018-08-11T20:06:02+0800
     * @param    [type]                   $id [description]
     * @return   [type]                       [description]
     */
    public function cartypeInfo($id)
    {
        return $this->field('ID,NAME,LOGO_PATH,CREATE_TIME,MODIFY_TIME')->where("CAR_STATUS","NEQ","9")->find($id);
    }
    /**
     * 编辑车辆品牌 图标
     * @author 王涛
     * @DataTime 2018-08-11T21:14:04+0800
     * @param    [type]                   $data [description]
     * @return   [type]                         [description]
     */
    public function cartypeEdit($data)
    {
        return $this->where('ID', $data['ID'])->update($data);
    }
    /**
     * 统计车辆品牌 数量
     * @author 王涛
     * @DataTime 2018-08-11T21:15:17+0800
     * @return   [type]                   [description]
     */
    public function cartypeCount($w=array('P_ID'=>'0'))
    {
        return $this->where($w)->count();
    }

    /**
     * Notes: 根据id修改车辆品牌名|车系名|车型名
     * Create Date: 2018/10/24
     * Create by :lijie
     */
    public function editCarType($w,$save)
    {
        return $this->where($w)->update($save);
    }

}